import { stringify } from 'qs';
import request from '../utils/request';

export async function queryProjectNotice() {
  return request('/apis/project/notice');
}
export async function queryCheck(params) {
    return request.get(`/api/user/check/${params.id}`);
}
export async function queryService(params) {
    return request.get('/api/service', {params});
}
export async function addService(params) {
    return request.post('/api/service', params);
}
export async function changeService(params) {
    return request.post('/api/service', params);
}
export async function queryCategories() {
    return request.get('/api/service_menus');
}
export async function queryActivities() {
  return request('/apis/activities');
}

export async function queryDashBoard() {
  return request.get(`/api/dashboard?`);
}

export async function queryChargeList(params) {
  return request.get('/api/user/charge', {params});
}
export async function queryCashList(params) {
    return request.get('/api/user/cash', {params});
}

export async function queryCashCheck(params) {
    if(params.ids){
        return request.post('/api/user/cash/check', {ids:params.ids});
    }else {
        const ids = params.map((item)=>{ return item.id});
        return request.post('/api/user/cash/check', {ids});
    }
}
export async function queryUnCashCheck(params) {
    return request.post('/api/user/cash/uncheck', params);
}
export async function queryAdvert(params) {
    return request.get('/api/avd/avd', {params});
}
export async function queryAdvertItem(params) {
    return request.get(`/api/avd/avd/${params.id}`);
}
export async function removeAdvert(params) {
    return request.delete(`/api/avd/avd/${params.id}`);
}
export async function addAdvert(params) {
    return request.post(`/api/avd/avd`,params);
}
export async function editAdvert(params) {
    return request.put(`/api/avd/avd/${params.id}`,params);
}

//轮播图
export async function querySlider(params) {
    return request.get('/api/avd/slider', {params});
}
export async function querySliderItem(params) {
    return request.get(`/api/avd/slider/${params.id}`);
}
export async function removeSlider(params) {
    return request.delete(`/api/avd/slider/${params.id}`);
}
export async function addSlider(params) {
    return request.post(`/api/avd/slider`,params);
}
export async function editSlider(params) {
    return request.put(`/api/avd/slider/${params.id}`,params);
}

//优惠券
export async function queryCoupon(params) {
    return request.get('/api/user/coupon', {params});
}
export async function queryCouponItem(params) {
    return request.get(`/api/user/coupon/${params.id}`);
}
export async function removeCoupon(params) {
    let ids = params.items.map((item)=>{
        return item.id;
    })
    console.log(ids);
    return request.post(`/api/user/coupon/delete`,{ids:ids});
}
export async function addCoupon(params) {
    return request.post(`/api/user/coupon`,params);
}

export async function editCoupon(params) {
    if(params.items){
        params.ids = params.items.map((item)=>{
            return item.id;
        })
    }
    return request.put(`/api/user/coupon`,params);
}

export async function queryCouponGroup(params) {
    return request.get('/api/coupon/group', {params});
}

export async function addCouponGroup(params) {
    return request.post(`/api/coupon/group`,params);
}

export async function deleteCouponGroup(params) {
    return request.delete(`/api/coupon/group/${params.id}`,params);
}
export async function editCouponGroup(params) {
    return request.put(`/api/coupon/group/${params.id}`,params);
}
export async function addRule(params) {
  return request('/apis/rule', {
    method: 'POST',
    body: {
      ...params,
      method: 'post',
    },
  });
}

export async function fetchConfigData() {
    return request.get('/api/setting/config');
}
export async function saveConfigData(params) {
    return request.put('/api/setting/config/save',params);
}

export async function fakeSubmitForm(params) {
  return request('/apis/forms', {
    method: 'POST',
    body: params,
  });
}

export async function fakeChartData() {
  return request('/apis/fake_chart_data');
}

export async function queryTags() {
  return request('/api/tags');
}

export async function queryBasicProfile() {
  return request('/apis/profile/basic');
}

export async function queryAdvancedProfile() {
  return request('/apis/profile/advanced');
}

export async function queryFakeList(params) {
  return request(`/apis/fake_list?${stringify(params)}`);
}

export async function AccountLogin(params) {
   return request.post('/api/token', params);
}

export async function fakeMobileLogin(params) {
  return request('/apis/login/mobile', {
    method: 'POST',
    body: params,
  });
}

export async function fakeRegister(params) {
  return request('/apis/register', {
    method: 'POST',
    body: params,
  });
}

export async function queryNotices() {
  return request('/apis/notices');
}
